#coding=utf-8
from django.db import models
from django.contrib.auth.models import User
from image.models import Image

class CategoryManager(models.Manager):
    pass

class Category(models.Model):
    name = models.CharField(max_length=64)
    sequence = models.IntegerField(default=0)
    created_time = models.DateTimeField(auto_now_add=True)

    objects = CategoryManager()

    class Meta:
        verbose_name = u'分类'
        verbose_name_plural = u'分类列表'
        db_table = "t_category"
        ordering = ["sequence"]

    def __unicode__(self):
        return "%s"%self.name

class QuestionManager(models.Manager):
    pass

class Question(models.Model):
    PUBLIC_BOTH = 0
    PUBLIC_MALE = 1
    PUBLIC_FEMALE = 2
    PUBLIC_NONE = 3
    PUBLIC_CHANNEL_CHOICES =  ((PUBLIC_NONE, u'不公开'), (PUBLIC_BOTH, u'公开'), (PUBLIC_MALE,u'对男性公开'), (PUBLIC_FEMALE,u'对女性公开'))
    
    user = models.ForeignKey(User)
    image = models.ForeignKey(Image)
    category = models.ForeignKey(Category)
    content = models.TextField()
    public_channel = models.IntegerField(choices=PUBLIC_CHANNEL_CHOICES, default=PUBLIC_BOTH, verbose_name=u"公开类型")
    sns_channel = models.IntegerField(default=0)
    
    # 需要标明是向谁提问
    created_time = models.DateTimeField(auto_now_add=True)

    objects = QuestionManager()

    class Meta:
        verbose_name = u'问题'
        verbose_name_plural = u'问题列表'
        db_table = "t_question"
        ordering = ["-created_time"]
        
    def __unicode__(self): 
        return u"qid_%d" % self.pk

    def get_absolute_url(self):
        return "/question/%d/"%(self.id)



class FriendQuestion(models.Model):
    question = models.ForeignKey(Question)
    friend = models.ForeignKey(User)
    created_time = models.DateTimeField(auto_now_add=True)  

    class Meta:
        verbose_name = u"friend_question"
        verbose_name_plural = u"friend_question_list"
        db_table = "t_friend_question"
        ordering = ["-created_time"]



